package com.lijinjiang.component;

import com.lijinjiang.constant.Colors;

import javax.swing.*;
import java.awt.*;

/**
 * @Description 自定义列表渲染器
 * @Author lijinjiang
 * @Date 2024-12-30 10:52
 */
public class CustomListCellRender<E> extends JLabel implements ListCellRenderer<E> {
    public CustomListCellRender() {
        setOpaque(true);
    }

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        setText(value.toString());
        setHorizontalAlignment(JLabel.CENTER);
        setBackground(isSelected ? Colors.BG_SELECTED : Color.white);
        setForeground(isSelected ? Colors.FG_SELECTED : Color.black);
        this.setPreferredSize(new Dimension(this.getWidth(), 20));
        this.setFont(new Font("宋体", Font.PLAIN, 14));
        return this;
    }
}
